<template>
	<view class="list_wrap">
		<scroll-view v-if="notices.length > 0" scroll-x="false" scroll-y="true" @scrolltolower="getNotices">
			<view class="item" v-for="(item, index) in notices" :key='index' @click="handleToDetail(item.id)">
				<text>{{item.title}}</text>
				<view>{{item.createTime}}</view>
			</view>
		</scroll-view>
		<view v-else>
      <no-data  />
		</view>
	</view>
</template>

<script>
	import {
		getNoticeList
	} from "@/config/api.js";
  import NoData from "@/components/noData.vue";
	let notId;
	export default {
    components: {NoData},
		data() {
			return {
				notices: [],
				hasMore: true,
				pages: {
				  pageNum: 1,
				  pageSize: 10,
				},
				loadMore: true,
				notId:""
			}
		},
		onLoad: (options) => {
			notId = options.id
		},
		onShow() {
		  this.loadMore = true;
		  this.pages = {
		    pageNum: 1,
		    pageSize: 10,
		  };
		  this.notices = [];
		 this.getNotices(notId);
		},
		methods: {
			//点击调转详情
			handleToDetail(id) {
				uni.navigateTo({
					url: `/page_index/notice/detail?id=${id}`
				})
			},
			//获取公告列表
			getNotices(id) {
				if (!this.loadMore) {
				  return;
				}
				getNoticeList({
						...this.pages,
						channelId:id
					})
					.then((res) => {
						if (res.code === 200) {
							if (res.rows.length > 0) {
								this.notices.push(...res.rows);
								if (this.notices.length < res.total) {
									this.loadMore = true;
									this.pages.pageNum = this.pages.pageNum + 1;
								} else {
									this.loadMore = false;
								}
							}
						}
					})
					.catch((err) => console.log("错误了", err));
			}
		}
	}
</script>

<style lang="scss" scoped>
	.list_wrap {
		width: 100%;
		box-sizing: border-box;
		padding: 0 32rpx;

		.item {
			box-sizing: border-box;
			padding: 24rpx;
			background: #F7F9FA;
			border-radius: 24rpx 24rpx 24rpx 24rpx;
			margin-top: 24rpx;

			text {
				width: 100%;
				font-size: 28rpx;
				font-weight: 400;
				color: rgba(0, 0, 0, 0.8);
				line-height: 40rpx;
				display: -webkit-box;
				-webkit-line-clamp: 3;
				-webkit-box-orient: vertical;
				overflow: hidden;
				text-overflow: ellipsis;
			}

			view {
				font-size: 24rpx;
				font-weight: 400;
				color: rgba(0, 0, 0, 0.5);
				line-height: 34rpx;
				margin-top: 24rpx;
			}
		}
	}
</style>
